package com.kucowka.struts.actions.chat.history;

import java.util.Map;

import com.kucowka.struts.messages.Message;

public class HistorySaverImpl implements HistorySaver {

	private StringSaver saver;

	public HistorySaverImpl(StringSaver saver) {
		this.saver = saver;
	}

	@Override
	public boolean saveMessages(Map<String, Message> messages) {

		boolean result = true;

		if (messages == null) {
			throw new NullPointerException("messages map cannot be null");
		}

		for (Map.Entry<String, Message> entry : messages.entrySet()) {
			if (!saver.writeString(entry.getKey() + ":"
					+ entry.getValue().getAuthor() + ":"
					+ entry.getValue().getContent())) {
				result = false;
				break;
			}
		}

		return result;
	}

	@Override
	public Message loadMessage(String uuid) {
		return null;
	}

}
